package com.youzikj.wx.comm.menu.menumanager;

import org.apache.catalina.util.URLEncoder;
import org.apache.log4j.Logger;

import com.youzikj.wx.comm.menu.Button;
import com.youzikj.wx.comm.menu.ClickButton;
import com.youzikj.wx.comm.menu.ComplexButton;
import com.youzikj.wx.comm.menu.Menu;
import com.youzikj.wx.comm.menu.ViewButton;
import com.youzikj.wx.comm.pojo.Token;
import com.youzikj.wx.comm.util.CommonUtil;
import com.youzikj.wx.comm.util.MenuUtil;

/**
 * 创建自定义菜单
 */
public class MenuManager {
	
	private static Logger log = Logger.getLogger(MenuManager.class);
	
	/**
	 * 定义菜单结构
	 * @return
	 */
	private static Menu getMenu(){
		ViewButton btn11 = new ViewButton();
		btn11.setName("微友传单");
		btn11.setType("view");
		//btn11.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxca78deeb014de180&redirect_uri=https%3a%2f%2fwycd.youzikj.com%2findex.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect");
		//btn11.setUrl("http://wycd.youzikj.com/wycd/menu");
		btn11.setUrl("http://open.weixin.qq.com/connect/oauth2/authorize?appid=wxca78deeb014de180&redirect_uri=http%3a%2f%2fwycd.youzikj.com%2fwycd%2fmenu&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect");
		//btn11.setUrl("http://wycd.youzikj.com/wycd/index1");
		//btn11.setUrl("https://wycd.youzikj.com/wycd/index");
		
		//		ClickButton btn12 = new ClickButton();
//		btn12.setName("ITeye");
//		btn12.setType("click");
//		btn12.setKey("iteye");
//		
//		ViewButton btn13 = new ViewButton();
//		btn13.setName("CocoaChina");	
//		btn13.setType("view");
//		btn13.setUrl("http://www.iteye.com");
//		
//		ViewButton btn21 = new ViewButton();
//		btn21.setName("淘宝");
//		btn21.setType("view");
//		btn21.setUrl("http://www.taobao.com");
//		
//		ViewButton btn22 = new ViewButton();
//		btn22.setName("京东");
//		btn22.setType("view");
//		btn22.setUrl("http://www.jd.com");
//		
//		ViewButton btn23 = new ViewButton();
//		btn23.setName("唯品会");
//		btn23.setType("view");
//		btn23.setUrl("http://www.vipshop.com");
//
//		ViewButton btn31 = new ViewButton();
//		btn31.setName("多泡");
//		btn31.setType("view");
//		btn31.setUrl("http://www.duopao.com");
//		
//		ViewButton btn32 = new ViewButton();
//		btn32.setName("一窝88");
//		btn32.setType("view");
//		btn32.setUrl("http://www.yi588.com");
//		
//		ComplexButton mainBtn1 = new ComplexButton();
//		mainBtn1.setName("技术交流");
//		mainBtn1.setSub_button(new Button[] {btn11,btn12,btn13});
//		
//		ComplexButton mainBtn2 = new ComplexButton();
//		mainBtn2.setName("购物");
//		mainBtn2.setSub_button(new Button[] {btn21,btn22,btn23});
//		
//		ComplexButton mainBtn3 = new ComplexButton();
//		mainBtn3.setName("网页游戏");
//		mainBtn3.setSub_button(new Button[] {btn31,btn32});
//		
		Menu menu = new Menu();
		menu.setButton(new Button[]{btn11});
		return menu;
	
	}

	public static void main(String[] args) {
		String appId = "wxca78deeb014de180";
		
		String appSecret = "1571230c181e897c0f0a492d1e2aa47c";
		
		String token = CommonUtil.getSingToken(appId, appSecret);
		System.out.println(token);
	//	String jst = CommonUtil.getSingJsapiTicket(CommonUtil.getSingToken(appId, appSecret));
	//	System.out.println(jst);
		if(null != token){
			//创建菜单
//			String menu = MenuUtil.getMenu(token.getAccessToken());
//			System.out.println(menu);
			//boolean result = MenuUtil.deleteMenu(token.getAccessToken());
			boolean result = MenuUtil.createMenu(getMenu(), token);
			if(result){
				System.out.println("成功创建菜单");
			} else{
				System.out.println("创建失败");
			}
			
		}
	}
	
}
